const crypto = require('crypto');
const key ="B8C37E33DEFDE51CF91E1E03E51657DA";


function getSign(params, key) {
    if (typeof params == "string") {//如果是字符串
        return paramsStrSort(params);
    } else if (typeof params == "object") {//如果是对象
        var arr = [];
        for (var i in params) {
                if(params[i]===undefined)
                    continue; //如果是undefined就跳出
                arr.push((i + "=" + params[i]));
            }
        return paramsStrSort(arr,key);
    }
}

function paramsStrSort(arr,key) {
    var unSignStr = arr.sort().join("&") + '&key=' + key;
    var md5 = crypto.createHash('md5');
    var signStr= md5.update(unSignStr,'utf-8').digest('hex').toUpperCase();
    return signStr;
}

export default function(pltRequestDomain) {
    return getSign(pltRequestDomain,key);
};